<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>活动投诉列表</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form">
            <div style="float: left; margin-left: 15px; margin-top: 20px;">
                <div class="demoTable">
                    <div class="layui-inline">
                        <label class="layui-form-label">用户名称:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="nickName" placeholder="请输入"
                                   autocomplete="off" class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">活动标题:</label>
                        <div class="layui-input-inline">
                            <input type="text" name="title" placeholder="请输入"
                                   autocomplete="off" class="layui-input"/>
                        </div>
                    </div>
                </div>
            </div>
            <!--搜索按钮-->
            <div class="layui-inline"
                 style="float: left; margin-left: 30px; margin-top: 20px;">
                <button class="layui-btn" lay-submit=""
                        lay-filter="data-search-btn">搜索
                </button>
            </div>

            <!--清空搜索框按钮-->
            <div class="layui-inline"
                 style="float: left; margin-left: 30px; margin-top: 20px;">
                <button type="reset" class="layui-btn">清空</button>
            </div>
        </form>
    </div>
</div>
<div style="float: left; margin-left: 10px;">
    <table id="ac_complainList" class="ac_complainList" lay-filter="ac_complainList"></table>
</div>
<script th:src="@{/src/layui.js}"></script>

<script>
    layui.use(['jquery', 'layer', 'laypage', 'laytpl', 'table','form'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            form = layui.form,
            laypage = layui.laypage,
            laytpl = layui.laytpl,
            table = layui.table;
        table.render({
            id: 'ac_complainList',
            elem: '#ac_complainList',
            url: '/ac_complain/list',
            title: '投诉列表',
            cellMinWidth: 80,
            page: true,
            limit: 5,
            limits: [5, 10, 20],
            cols: [
                [
                    {type: 'checkbox',width:80},
                    {title: '编号', field: 'id',width:80},
                    {title: '用户名', field: 'nickName',width:100},
                    {title: '性别', field: 'sex', templet: '#sexEdit',width:80},
                    {title: '邮箱', field: 'mailBox',width:170},
                    {title: '活动标题', field: 'title',width:130},
                    {title: '活动创建时间', field: 'createTime',width:130},
                    {title: '投诉内容', field: 'reason',width:130},
                    {title: '回复内容', field: 'context',width:130},
                    {title: '状态', field: 'status', templet: '#statusEdit',width:100},
                    {title: '操作', templet: '#barEdit',width:130}
                ]
            ],
            parseData: function (result) {
                return {
                    code: result.code == 200 ? 0 : result.code,
                    msg: result.message,
                    count: result.data.total,
                    data: result.data.list
                }
            }
        })
        table.on('tool(ac_complainList)', function (row) {
            var data = row.data;//获取当前行的数据
            var event = row.event;// 获得 lay-event 对应的值

            if (data.status === 1) {
                layer.msg("该投诉已回复！");
                return;
            }
            if (event === 'edit') {
                layer.open({
                    type: 2,
                    title: '投诉回复',
                    area: ['400px', '400px'],
                    content: '/ac_complain/reply/' + data.id
                });
            }
        })
        form.on('submit(data-search-btn)', function (data) {
            var nickName = data.field.nickName;
            var title = data.field.title;

            //执行重载
            table.reload('ac_complainList', {
                page: {
                    curr: 1
                },
                where: {
                    nickName: nickName,
                    title: title
                },
                method: 'get',
                url: '/ac_complain/select',
            });
            return false;
        });
    })
</script>

<script type="text/html" id="barEdit">
    {{# if (d.status==0) { }}
    <a class="layui-btn layui-btn-xs layui-btn-disabled" lay-event="edit" shiro:lacksPermission="sys:acc:reply">回复</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit" shiro:hasPermission="sys:acc:reply">回复</a>
    {{# }else{ }}
    <span>该投诉已回复</span>
    {{# } }}
</script>

<script type="text/html" id="statusEdit">
    {{# if (d.status==0) { }}
    <span>未回复</span>
    {{# }else{ }}
    <span>已回复</span>
    {{# } }}
</script>

<script type="text/html" id="sexEdit">
    {{# if (d.status==0) { }}
    <span>男</span>
    {{# }else{ }}
    <span>女</span>
    {{# } }}
</script>
</body>
</html>